/**
 * @description 用户 Model Mongodb
 */

const mongoose = require('../db/mongoose')

const AdminSchema = new mongoose.Schema(
  {
    username: { type: String, unique: true, required: true },
    password: { type: String, required: true },
    nickName: { type: String, default: '' }, // 昵称
    latestLoginAt: { type: Date, default: null } // 最后登录时间
  },
  {
    timestamps: true,
    toJSON: {
      transform(doc, ret) {
        delete ret.password
        delete ret.__v
      }
    }
  }
)

const AdminModel = mongoose.model('Admin', AdminSchema)

module.exports = AdminModel
